####################################################
# Lighting Manager settings
#
# LIGHT FILE May 4


####################################################D
# Global diffusion parameters

# If auto-lighting is active, this has no absolute effect,
# but it does factor into how quickly lights fall off.
# The higher the ambient, the sooner the lights
# drop off to zero.
set outsideDiffusionAmbientColor    (1.0, 1.0, 1.0)
set outsideFloorAmbient                0.25
set outsideWallAmbient                 0.25

# These control how much the floor affects an adjacent
# wall for a wall with direct lighting, and a wall with
# no other lighting respectively.
set brightWallFloorContribution        1
set darkWallFloorContribution          .5


# Number of steps to use in the propagation algorithm.
# The higher this number is, the farther light will
# spread, but also the longer diffusion will take.
seti wallPropagationSteps 50
seti floorPropagationSteps 50

# strength of wall and floor bumpmapping, derived from
# diffusion map.
setf incidenceMapScale 100
setf incidenceMapHeightClamp 1



####################################################
# Automatic room lighting tuning constants
#

# Room object lighting algorithm
# 0 = 5 directionals, 1 = 4 directionals, 
# 2 = ambient, 3 = ambient + 1 dir, etc.
setf roomLightingType 4

# Multiplier on how brightly the objects are lit by 
# overall room lighting.
set roomOverallStrength 0.4
set sim:roomOverallStrength .8
set object:roomOverallStrength 0.5
set wall:roomOverallStrength 0.2
set wall:roomDirectionalBoost  1
setf wall:roomFromLightMapMix      1 
setf wall:roomFromLightMapStrength 3

#set roomOverallStrength 0
#set sim:roomOverallStrength 0
#set object:roomOverallStrength 0
#set wall:roomOverallStrength 0
#set floor:roomOverallStrength 0
#set wall:roomDirectionalBoost  0
#setf wall:roomFromLightMapMix      0
#setf wall:roomFromLightMapStrength 0

# strength of room object bounce light
set roomBounceStrength 0.25 
# The amount of "crossover" from the side lights.
set roomBounceCrossover 1


# Bounce crossover determines how much of the sampled 
# side lighting leaks into the bounce light. (The 
# underside of a surface can usually see portions of the
# walls.)

# strength & crossover of room object side lights
set roomSideStrength  1.2
set roomSideCrossover 1
# slope of room object side lights -- zero is
# horizontal, 1 is pointing down at a 45 degree
# angle.
set roomSideSlope 0.75

# This controls how much of the wall and floor colours
# bleed into the object lighting. 1 gives full bleed,
# 0 gives none at all.
set roomSaturation 0.5

# How much direct lighting from portals (windows/doors) affects
# Sim/object lighting.
set roomPortalStrength .75

# How much to bias lighting so we get secondary variation
# at ninety degrees to the major light direction.
set roomCrossBias 0
set object:roomCrossBias 0
set sim:roomCrossBias 0

# How much to over- or under-emphasize directional aspect
# of room lighting.
set object:roomDirectionalBoost 4
set sim:roomDirectionalBoost 4
# Ceiling light proportional to floor.
# (There is no actual ceiling, so illumination from
# the ceiling is estimated as a fraction of the floor
set roomCeilingStrength 1


# Light-map derived room lighting
setf sim:roomFromLightMapMix      0 # controls mix with trad. room lighting
setf sim:roomFromLightMapStrength 2  # multiplier on light-map derived lighting

setf object:roomFromLightMapMix      0  # controls mix with trad. room lighting

# How much the room lights contribute to specular
# reflection. Be careful: setting this value to
# a high value may result in many more specular
# highlights than you want, leading to flashing.
set roomSpecular 0.8



####################################################
# Features

set wallDrivenPortals 1
# whether to use morning/evening states
setb morningEvening false

# Random jitters on practical light strengths
setf objectLightJitter 0
setf portalLightJitter 0

# Brightness at which light influences are cut off
# Be extremely careful in modifying this, because
# it affects how much lights overlap each other. If
# it's set too low, too many lights will overlap an
# object or Sim, leading to light popping.
set lightRangeCutoff 0.275

# How far out from the wall you have to be before
# a window/door spill light takes effect.
setf spillPlaneOffset 0.1

# How long lighting updates take (in seconds) when
# and object light turns on or off.
setf objectLightTransitionTime 0.1



####################################################
# Adjacent Portal Brightness Suppression

# the distance (in tiles) at which suppression drops to zero
# With 2 we only get suppression from windows on the adjacent 
# tiles.
set portalSuppressionRadius 4


# the amount of suppression to apply. if the suppressing
# portal light is 'r' units away, the suppression is 
#    1 - (1 - r/R) * f
# where 'f' is the suppression amount, and 'R' the suppression
# radius.
set portalSuppressionAmount .2



####################################################
# Environment light maps (for lighting terrain/floors/
# walls outside.)
#

set dayLightMapID    0xeba01cc9
set nightLightMapID  0x8ba01cad
set nhoodLightMapID  0x0be702ef
set testMap1ID       0x917660c
set testMap2ID       0x917660d


####################################################
# Height map shadows
#

setf hmLotShadowStrength         1.5
setf hmNHoodShadowStrength       0.47
setf hmSunLightTransitionZone    1
setf hmBlobWidthModifier         0.05
setf hmBlobHeightModifier        .09
setf hmObjectShadowingBias       0.09
setf hmBinaryShadowThreshold     0.99



####################################################
# Time of day lighting states
#


####################################################
# Daytime
#
lightingState day
   control -edith true

   # outside direct lighting
   skylight                      (1,1,1)  0.5
   light sun      (1.5, 1.2, 2)    (1, .94, .875)     2
   light sky      (-1.5, -1.2, 2)  (.8,.8,.8)    .5
   light fill1    (1, 1, -1)     (1,0.8,.9)    .5

   light simFill1  (1, -1.2, 1) (1, .95, .89)  .5
   light simFill2  (-2, 2, 1) (1, .95, .89)  1.75

   # inside diffusion
   diffParam insideAmbientColor       (.85, .75, .75)  
   diffParam insideFloorAmbient         0.001  
   diffParam insideWallAmbient          0.001  
   
   # diffusion inside and outside
   diffParam floorThreshold           .4
   diffParam wallThreshold            .4
   
   portalSaturation 1

   # modifiers <type> <practicalStrength:float> <diffusionStrength:float> [<practicalFalloff:float> <diffusionFalloff:float>] 
   
   #                           pract. diffuse  p. falloff  d. falloff
   modifiers insidePortals       0.5  .7          1.3    1
   modifiers insidePortalSpills   .9     .8         .4    .9  #### check after incremental
   modifiers outsidePortals      0       0          1           1
   modifiers outsidePortalSpills 0       0          1           1


   #                         pract. diffuse  p. falloff  d. falloff
   modifiers insideObjects     .8       .7    .35   .5  ### this can go higher when the on/off is fixed
   modifiers outsideObjects    0       0         1 1


  projectiveShadowStrength 0.73

 # modifiers insideObjects  0 0 0 0
 # modifiers insidePortals      0       0         0 0
 #  modifiers insidePortalSpills 0       0          0 0

   # extra ambient for unlit rooms.
   unlitRoomColor (.3, .275, .275) -threshold .33
   unlitRoomColor (.45, .425, .4) -threshold .4
   flatShade (1, .95, .85) .75  -sims 1.7 -objects 1.3 -indoors 1 # for lighting set to low.

   environment (1, 1, 1) 1
   
   #               max in time (s)   max out time (s)
   transitionTimes        2                 100
end




# This state is used instead when portal lighting is disabled --
# currently when lighting is set to "medium"
lightingState dayNoPortals : day
   # could do stuff here to compensate for lack of portals.
   # diffusion inside and outside
end


####################################################
# Nighttime
#
lightingState night
   control -edith true
   
   skylight                         (0.25, 0.25, 0.3)     0.75
   light sun      (-1.5, -1,  2)    (.45, .45, 1)      0.6
   # light sun      (-1.5, -1,  2)    (.3, .3, .95)      .6
   light sky      ( 1.5,  1, 1)    (.25, 0.25, 1)    .6

  light simFill1  (-1.25, -.75, 1.2) (.82,.8, .8)  1
  light simFill2  (1.25, .75, 1.2) (.82,.8, .8)  .6
   
   diffParam insideAmbientColor  (.9,.9,1)
   diffParam insideFloorAmbient   .001
   diffParam insideWallAmbient    0.001

   
   diffParam floorThreshold          0.2
   diffParam wallThreshold           0.2

   #                              pract. diffuse  p. falloff  d. falloff
   modifiers insidePortals         0      .2      1 1
   modifiers insidePortalSpills    0      .2      1 1
   modifiers outsidePortals        4      4       .5         1
   modifiers outsidePortalSpills   4      4      .5         1

   #                         pract. diffuse  p. falloff  d. falloff
   modifiers insideObjects     .6    .6       .35       .65
   modifiers outsideObjects    1      .6        .4     .65
  # modifiers insidePortals      0       0         0 0
  # modifiers insidePortalSpills 0       0          0 0
  # modifiers outsidePortals      0       0         0 0
  # modifiers outsidePortalSpills 0       0          0 0

 projectiveShadowStrength 0.4
   # How much sun/skylight split in spill lights
   portalSaturation 1
   
   # extra ambient for unlit rooms.
   unlitRoomColor (0.345, 0.345, 0.42) -threshold .4 ### do not set threshold to 0
 ##   unlitRoomColor (0.245, 0.245, 0.32) -threshold .28
   flatShade (0.75, 0.8, 1)  .6 -sims 1.8 -objects 1.5 -indoors 1 # for lighting set to low

   environment (1, 1, 1) .8  # for env. cubes and particles #does not work

   #               max in time (s)   max out time (s)
   transitionTimes        2                 100
end

# This state is used instead when portal lighting is disabled --
# currently when lighting is set to "medium"
lightingState nightNoPortals : night
   # could do stuff here to compensate for lack of portals.
end




# these are currently unused.

####################################################
# Morning
#
lightingState morning
   control -edith true
   
   skylight                       (0.45, 0.25, 0.35)   0.52
   light sun      (-1.5, 1.5, 2)  (.95, .355, .75)     1.455
   light sky      (-.75, -.25, 1) (.655, 0.4, .455)    0.85

   diffParam insideAmbientColor     (.655, 0.3, .455)
   diffParam insideFloorAmbient     0.255
   diffParam insideWallAmbient      0.255
   
   diffParam floorThreshold       0.237
   diffParam wallThreshold        0.537   

   modifiers insidePortals 6.55 1.25
   modifiers outsidePortals 6.55 1.25

   # UI Lighting Parameter (based on but not identical to skyLight param.)
   UIShade (0.695, 0.699, 0.824)  1

   environment (0.45, 0.25, 0.35) 2  # for env. cubes and particles
   
   fog (0.8, 0.6, 0.6) 10 200
end
  

####################################################
# Evening
#
lightingState evening
   control -edith true
   
   skylight                       (0.45, 0.25, 0.35) 0.6
   light sun      (1.5, -1.5, 2)  (.95, .455, .75)   1.455
   light sky      (.75, .25, 1)   (.655, 0.4, .455)  0.85

   diffParam insideAmbientColor     (.95, .455, .75)
   diffParam insideFloorAmbient     0.255
   diffParam insideWallAmbient      0.255
   
   diffParam floorThreshold       0.237
   diffParam wallThreshold        0.537

   modifiers insidePortals 6.1 1.1
   modifiers outsidePortals 6.1 1.1

   # UI Lighting Parameter (based on but not identical to skyLight param.)
   UIShade (0.656, 0.531, .559)     1

   environment (0.45, 0.25, 0.35) 2  # for env. cubes and particles
end



####################################################
# Neighbourhood
#
lightingState neighbourhood
   # outside direct lighting
  # skylight (0.65, 0.65, .95) 1
  # light sun    ( 1, -2, 2)     (.9, .855, .8) 1.6
  # light sky    (-1,  2, 1)     (.8, .8, 1)  .9 
 # skylight                      (.87,.925,1)  0.5
  # light sun      (1.5, 1.2, 2)    (1, .94, .875)     1.75
   # light sky      (-1.5, -1.2, 2)  (.8,.8,.8)    .25
    # light fill1    (1, 1, 1)     (1,1,1)    .15

   
  skylight                      (.87,.925,1)  .25
   light sun      (1.75, -2, 1.5)    (1, .9, .8) 1.75
   light sky      (-2, 1.75, 2)  (0.7,.75,.8)   .5
   light fill1    (0, 0, 1)     (1,1,1)     0.25

   lightMap   $nhoodLightMapID
   
   # inside diffusion
   diffParam insideAmbientColor       (1, .95, .75)
   diffParam insideFloorAmbient        .15 
   diffParam insideWallAmbient         .25 
   
   # diffusion inside and outside
   diffParam floorThreshold            0.154
   diffParam wallThreshold             0.12
   
   #               pract. diffuse  p. falloff  d. falloff
   modifiers insidePortals       3      3.8        0.8         .9
   modifiers insidePortalSpills  3      4          .8         1.3
   
   modifiers outsidePortals      0       0          1           1
   modifiers outsidePortalSpills 0       0          1           1

   #                         pract. diffuse  p. falloff  d. falloff
   modifiers insideObjects     1       1         2        1 
   modifiers outsideObjects    0.5     1         4         2  


   # extra ambient for unlit rooms.
   unlitRoomColor (0.01, 0.01, 0.01)
   
   # fog <colour> <nearRange> <farRange>
   # DISABLED pending shader program path support for linear fog.
   #fog (0.9, 0.9, 1) 1200 2200

   flatShade (1, .95, .85) .75  # for lighting quality 0
end

# Only here because the fallback path is currently broken.
lightingState neighbourhoodNoPortals : neighbourhood
   lightMap $nhoodLightMapID
end

# Used to generate imposters from lot houses.
lightingState neighbourhoodImposter : neighbourhood


 skylight                      (.87,.925,1)  0.5
   light sun      (-2, -2, 1.5)  (1, .9, .8) 1.5
   light sky      (2, 2, 2)  (.7,.75,.8)   .35
   light fill1    (0,0,1)   (1,1,1)     .25
      
   lightMap  0 # disable light map
# lightMap $nhoodLightMapID
   # inside diffusion
   diffParam insideAmbientColor       (.75, .75, .75)  
   diffParam insideFloorAmbient         0.001  
   diffParam insideWallAmbient          0.001  
   
   # diffusion inside and outside
   diffParam floorThreshold            .4
   diffParam wallThreshold             .4
   
   portalSaturation 1

   # modifiers <type> <practicalStrength:float> <diffusionStrength:float> [<practicalFalloff:float> <diffusionFalloff:float>] 
   
   #                           pract. diffuse  p. falloff  d. falloff
   modifiers insidePortals       1.25 1.25           .5          .5
   modifiers insidePortalSpills  1.25 1.25           .5          .5
   
   
   modifiers outsidePortals      0       0          1           1
   modifiers outsidePortalSpills 0       0          1           1

   #                         pract. diffuse  p. falloff  d. falloff
   modifiers insideObjects     .9        .75    .33  0.5
   modifiers outsideObjects    0       0         1 1
    
   # extra ambient for unlit rooms.
   # Alon's values: unlitRoomColor (.1, .1, .09) -threshold .4   
   unlitRoomColor (.275, .275, .275) -threshold .33
#  unlitRoomColor (0,0,0) -threshold .33
   #lightMap $dayLightMapID -strength 1

   # UI Lighting Parameter (based on but not identical to skyLight param.)
   UIShade (1, 1, 1) 1   
    
   flatShade (1, .95, .85) 0.7  # for lighting set to low.

   environment (1, 1, 1) 1

end

# For testing only.
lightingState neighbourhoodHiC
   # uses original SC4 light map. makes it easier
   # to see where the shadows are for testing.

   # outside direct lighting
   light sun   (-0.5,  1, 0.5)   (.9, .855, .8)    4
   light sky   ( 0.5, -1, 0.5)   (.8, .8, 1)       .5
   
   light fill1 (-1, -1, -1)      (1, 1, 0.75)      0.75
   light fill2 (-1, 1, -.5)      (0.6, 0.5, 0.45)  0.5
           
   lightMap $testMap1ID
   
   # fog colour nearRange farRange.
   # original:
   # fog (0.9, 0.9, 1) 350 1050
   # tweaked for new zooms:
   #fog (0.9, 0.9, 1) 700 1800
    
end



####################################################
# CAS
#
lightingState CAS
    # outside direct lighting
   skylight                      (.87,.925,1)  0.3
   light sun      (1.5, 1, 2)    (1, .94, .875)      1
   light sky      (-1.5, -1, 2)  (.8,.8,.8)    .5
   light fill1    (1, 1, 1)     (1,1,1)    .5

  # light simFill1  (1.5, 1, 2) (1, 1, 1)  0.5
  # light simFill2  (-2, -1, 2) (1, 1, 1)  .5

   # inside diffusion
   diffParam insideAmbientColor       (0,0,0)  
   diffParam insideFloorAmbient         0.001  
   diffParam insideWallAmbient          0.001  
   
   # diffusion inside and outside
   diffParam floorThreshold            .25
   diffParam wallThreshold             .25
   
   portalSaturation 1

   # modifiers <type> <practicalStrength:float> <diffusionStrength:float> [<practicalFalloff:float> <diffusionFalloff:float>] 
   
   #                           pract. diffuse  p. falloff  d. falloff
   modifiers insidePortals       1    0.75           .8        1
   modifiers insidePortalSpills  0   .25           .65          1
   
   
   modifiers outsidePortals      0       0          1           1
   modifiers outsidePortalSpills 0       0          1           1

   #                         pract. diffuse  p. falloff  d. falloff
   modifiers insideObjects     1    .75   .33    .4
   modifiers outsideObjects    0       0         1 1
    
   # extra ambient for unlit rooms.
   # Alon's values: unlitRoomColor (.1, .1, .09) -threshold .4   
   unlitRoomColor (.175, .142, .1) -threshold .175
   unlitRoomColor (.2, .172, .15) -threshold .175
#  unlitRoomColor (0,0,0) -threshold .33
   #lightMap $dayLightMapID -strength 1

   # UI Lighting Parameter (based on but not identical to skyLight param.)
   UIShade (1, 1, 1) 1   
    
   flatShade (1, .95, .85) 0.7  # for lighting set to low.

   environment (1, 1, 1) 1
end



####################################################
# Debugging
#

lightingState test
   light sun      (1, 0, 0)   (1, 0, 0)  1
   light sky      (0, 1, 0)   (0, 1, 0)  1
   light fill1    (0, 0, 1)   (0, 0, 1)  1
   light fill2    (-1, -1, -1)   (1, 1, 0) 1
   
   diffParam insideAmbientColor       (1, 1, 1)
   diffParam insideFloorAmbient        0
   diffParam insideWallAmbient         0.0
   
   diffParam floorThreshold            0.1
   diffParam wallThreshold             0.1   

   modifiers insidePortals 0 0
   modifiers outsidePortals 0 0
   modifiers insideObjects 0 0
   modifiers outsideObjects 0 0

   # UI Lighting Parameter (based on but not identical to skyLight param.)
   UIShade (0, 0, 0) 0
   
   environment (1, 0, 1)
end


# Intended to show object lights in isolation.
lightingState debugObjects   
   
   # inside diffusion
   diffParam insideAmbientColor       (.8, .75, .75)  
   diffParam insideFloorAmbient         .1  
   diffParam insideWallAmbient          .2   
   
   # diffusion inside and outside
   diffParam floorThreshold            0.154
   diffParam wallThreshold             0.12
   
   #                         pract. diffuse  p. falloff  d. falloff
   modifiers insideObjects     1       1          1           1
   modifiers outsideObjects    1       1          1           1

   environment (0, 0, 0) 
end

# Intended to show object light diffusion seeds.
lightingState debugObjectSeeds : debugObjects
   
   #                         pract. diffuse  p. falloff  d. falloff
   modifiers insideObjects     0       1          1           100
   modifiers outsideObjects    0       1          1           100
end

lightingState debugPortals
   control -debugPortals true
   
   light sun      (-1, 0, 0)  (0, 0, 0)
   light sky      (1, 0, 0)   (0, 0, 0)
   light fill1    (0, 0, -1)  (0, 0, 0)
   light fill2    (0, 0, 1)   (0, 0, 0)
   
   diffParam insideAmbientColor       (1, 1, 1)
   diffParam insideFloorAmbient        0
   diffParam insideWallAmbient         0

   diffParam floorThreshold            10
   diffParam wallThreshold             1
   
   modifiers insidePortals  1000 2
   modifiers outsidePortals 1000 2
   modifiers insidePortalSpills  0 0
   modifiers outsidePortalSpills 0 0
   modifiers insideObjects  0 0
   modifiers outsideObjects 0 0

   environment (0, 0, 0)
end

lightingState debugPortalSpills
   control -debugPortals true
   
   light sun      (-1, 0, 0)  (0, 0, 0)
   light sky      (1, 0, 0)   (0, 0, 0)
   light fill1    (0, 0, -1)  (0, 0, 0)
   light fill2    (0, 0, 1)   (0, 0, 0)
   
   diffParam insideAmbientColor       (1, 1, 1)
   diffParam insideFloorAmbient        0
   diffParam insideWallAmbient         0

   diffParam floorThreshold            10
   diffParam wallThreshold             1
   
   modifiers insidePortalSpills  1000 2
   modifiers outsidePortalSpills 1000 2
   modifiers insidePortals  0 0
   modifiers outsidePortals 0 0
   modifiers insideObjects  0 0
   modifiers outsideObjects 0 0

   environment (0, 0, 0)
end

# Material tuning flat lighting states
# Flat ambient illumination of the given percentage.
lightingState mat000
   skylight                     (0, 0, 0)
   flatShade                    (0, 0, 0)
   environment                  (0, 0, 0)
   
   diffParam insideAmbientColor (0, 0, 0)  

   diffParam insideFloorAmbient         0.5
   diffParam insideWallAmbient          1
      
   modifiers insidePortals       0       0           
   modifiers outsidePortals      0       0              
   modifiers insidePortalSpills  0       0           
   modifiers outsidePortalSpills 0       0              
   modifiers insideObjects       0       0         
   modifiers outsideObjects      0       0         
end

define matState(pct)
   set shade (&pct / 100)
   lightingState mat&{pct} : mat000
      skylight                     ($shade, $shade, $shade)
      flatShade                    ($shade, $shade, $shade)
      environment                  ($shade, $shade, $shade)
      diffParam insideAmbientColor ($shade, $shade, $shade)     
   end
enddef

create matState(050)
create matState(100)
create matState(150)
create matState(200)
create matState(300)
create matState(400)





####################################################
# External lighting
#


# Strength of outdoor lighting for walls/objects.
# Ideally these would both be 1, and our object
# materials would all be tuned to look consistent
# with such lighting. But that's not
# the case at the moment.
setf outdoorStrength 1
# terrain strength is currently specified separately.
setf terrainStrength 1


####################################################
# Light map parameters
#
# Don't touch unless you know what you're doing.

# these are actually page sizes
seti floorTextureSize 512
seti wallTextureSize 256

# 4/8 triggers direct guard tile->texture mapping.
# Otherwise, need y = 3 * x.
seti wallTileSizeX 8
seti wallTileSizeY 24

setb lightMapDebug false


####################################################
# Lighting overrides
#

# Light overrides are in a separate file
include "LotLights.txt"

